package com.xiaoge.demo.configs;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 作者：guoyzh
 * 时间：2019/4/12 19:42
 * 功能：swagger配置类 访问地址:http://127.0.0.1:8888/doc.html
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    @Value("${spring.profiles.active}")
    private String env; // 当前激活的配置文件

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable("dev".equals(env))
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoge.demo"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("小程序文档")
                .description("文档")
                .termsOfServiceUrl("http://www.unionglasses.com")
                .contact("developer@mail.com")
                .version("1.0")
                .build();
    }
}